<?php
   
   //登陆注册post
   //引入连接数据库
   @include_once('connect.php');

    $res = [];

    $username = $_POST['username'];
    $password = $_POST['password'];

    // $username = 'bb';
    // $password = 123;

    if($username && $password){
        $sql = "SELECT * FROM user2 WHERE username='$username'";
        $ggo = mysqli_query($connect , $sql);
        $arr = mysqli_fetch_array($ggo);
        
        if($arr > 0){
            $res['status'] = false;
            $res['msg'] = '用户已注册';
        }else{
            //插入数据
            $sql = "INSERT INTO user2 (username , password) VALUES ('$username' , '$password') ";
            $ggo = mysqli_query($connect , $sql);
            
            //$ggo在sql中返回的是受影响的行数，在这里也返回的是受影响的函数,是一个数字
            if($ggo > 0){
                $res['status'] = true;
                $res['msg'] = '注册成功';
            }else{
                $res['status'] = false;
                $res['msg'] = '数据库错误';
            }
            
        }
    }else{
        $res['status'] = false;
        $res['msg'] = '前端数据错误';
    }

    echo(json_encode($res , JSON_UNESCAPED_UNICODE));